package com.ruoyi.web.controller.mongo;

import com.ruoyi.mongo.cet4.service.PrimaryInterface;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.mongo.word.entity.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController()
@RequestMapping("/word_primary")
public class WordPrimaryController {

    @Autowired
    private PrimaryInterface primaryInterface;

    /**
     * 单元、书名查询
     */
    @GetMapping("/listByUnit")
    public AjaxResult getListByUnit(@RequestParam String unit, @RequestParam String book) {
        List<?> dataByUnit = primaryInterface.getListData(unit, book);
        return AjaxResult.success(dataByUnit);
    }

    /**
     * 学习记录
     * 列表
     */
    @GetMapping("/listStudyPage")
    public AjaxResult getListStudyPage(@RequestParam String unit, @RequestParam String book) {
        List<?> dataByPage = primaryInterface.getStudyData(unit, book);
        return AjaxResult.success(dataByPage);
    }

    /**
     * 学习记录
     * 保存
     */
    @PostMapping("/putStudyData")
    public AjaxResult putStudyData(@RequestBody WordStudyEntity entity) {
        primaryInterface.saveStudyData(entity);
        return AjaxResult.success();
    }

    /**
     * 添加测试记录
     * 保存
     */
    @PostMapping("/putTestList")
    public AjaxResult putTestList(@RequestBody WordSubmitEntity entity) {
        primaryInterface.saveTestData(entity);
        return AjaxResult.success();
    }

    /**
     * 按单元、书名查询
     * 按测试范围生成数据
     */
    @GetMapping("/listUnitTimes")
    public AjaxResult getListUnitTimes(@RequestParam(required = false) String unit,
                                       @RequestParam(required = false) int times,
                                       @RequestParam String book) {
        List<WordPrimaryEntity> list = primaryInterface.getListData(unit, book, times);
        return AjaxResult.success(list);
    }

    /**
     * 测试
     * 详情
     * 从新数据库中查询数据
     */
    @GetMapping("/getTestDetail/v1")
    public AjaxResult getTestDetail(@RequestParam String practice) {
        List<WordCheckNewRecord> list = primaryInterface.getTestDetail(practice);
        return AjaxResult.success(list);
    }

    /**
     * 测试
     * 详情-兼容旧数据库
     * 自动获取用户
     */
    @GetMapping("/getTestDetail")
    public AjaxResult getTestDetail(@RequestParam String practice, @RequestParam int way) {
        List<?> list = primaryInterface.getTestDetail(practice, way);
        return AjaxResult.success(list);
    }

    /**
     * 测试
     * 详情-兼容旧数据库
     * 从页面中获取用户
     */
    @GetMapping("/getTestDetail/v3")
    public AjaxResult getTestDetail(@RequestParam String practice, @RequestParam int way, @RequestParam Long user) {
//        List<?> list = primaryInterface.getTestDetail(practice,user, way);
        return AjaxResult.success();
    }

    /**
     * 汉译英
     * 保存
     */
    @PostMapping("/putWriteRecord")
    public AjaxResult putWriteRecord(@RequestBody WordChinToEngEntity entity) {
        primaryInterface.saveWriteData(entity);
        return AjaxResult.success("success");
    }

    /**
     * 汉译英
     * 查询
     */
    @GetMapping("/getWriteRecord")
    public AjaxResult getWriteRecord(@RequestParam String practice) {
        List<WordChinToEngEntity> data = primaryInterface.getWriteData(practice);
        return AjaxResult.success(data);
    }
}
